<body>
<script src="full-screen-test.js"></script>
<span></span>
<script>
    var span = document.getElementsByTagName('span')[0];

    var documentEnteredFullScreen = function() {
        testExpected("document.webkitCurrentFullScreenElement", document.documentElement);
        runWithKeyDown(function(){span.webkitRequestFullscreen()});
        waitForEvent(document, 'webkitfullscreenchange', spanEnteredFullScreen, false, true);
    };

    var spanEnteredFullScreen = function() {
        testExpected("document.webkitCurrentFullScreenElement", span);
        waitForEvent(document, 'webkitfullscreenchange', spanExited, false, true);
        document.webkitExitFullscreen();
    };

    var spanExited = function() {
        testExpected("document.webkitCurrentFullScreenElement", document.documentElement);
        waitForEvent(document, 'webkitfullscreenchange', documentExited, false, true);
        document.webkitExitFullscreen();
    };

    var documentExited = function() {
        testExpected("document.webkitCurrentFullScreenElement", undefined);
        endTest();
    };

    runWithKeyDown(function(){document.documentElement.webkitRequestFullscreen()});
    waitForEvent(document, 'webkitfullscreenchange', documentEnteredFullScreen, false, true);
</script>
